package com.ruoyi.result;

import com.ruoyi.constance.NumConstance;
import lombok.Data;

/**
 * @Program: book-web
 * @ClassName ResponseResult
 * @Description: 响应给客户端的统一响应对象实体
 * @Author: aimi
 * @Create: 2023-11-13 23:00
 * @Version 1.0
 **/
@Data
public class ResponseResult<T> {
    //响应码
    private Integer code;
    //响应的消息
    private String msg;
    //数据
    private T data;

    public static ResponseResult success(){
        ResponseResult<Object> responseResult = new ResponseResult<>();
        responseResult.setCode(NumConstance.RESPONSE_SUCCESS);
        responseResult.setMsg("");
        return responseResult;
    }
    public static <T> ResponseResult<T> success(T data){
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setCode(NumConstance.RESPONSE_SUCCESS);
        responseResult.setData(data);
        responseResult.setMsg("");
        return responseResult;
    }

    public static ResponseResult<String> error(String msg){
        ResponseResult<String> responseResult = new ResponseResult<>();
        responseResult.setCode(NumConstance.RESPONSE_ERROR);
        responseResult.setMsg(msg);
        return responseResult;
    }

    // token过期，当前为未登录状态
    public static ResponseResult<String> tokenError(String msg){
        ResponseResult<String> responseResult = new ResponseResult<>();
        responseResult.setCode(NumConstance.RESPONSE_NOT_LOGIN);
        responseResult.setMsg(msg);
        return responseResult;
    }
}